package com.tomehay.termprojectmanage_server.pojo.Model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.List;

import com.tomehay.termprojectmanage_server.mapper.ClazzMapper;
import com.tomehay.termprojectmanage_server.mapper.StudentMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 
 * </p>
 *
 * @author tomehay
 * @since 2023-06-20
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class Clazz {
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String clazzNo;

    private String departmentId;

    private String clazzName;

    private Integer clazzCount;

    private String invitationCode;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    public static boolean upDateStudentCount(StudentMapper studentMapper, ClazzMapper clazzMapper){
        List<Clazz> clazzList = clazzMapper.selectList(null);
        for (Clazz clazz : clazzList) {
            clazz.setClazzCount(studentMapper.GetCounts(clazz.id));
            clazzMapper.updateById(clazz);
        }
        return true;
    }
}
